<?php

include 'cellimage.php';
class CGridImage {
    //put your code here
    private $m_nRow ;
    private $m_nCol ; 
    private $m_nWidth;
    private $m_nHeight;
    
    private $m_nCellWidth;
    private $m_nCellHeight;
    private $m_nInthePage;
    private $m_bScroll;
    private $m_div;
    private $m_nNumber;

    public function isScroll($bScroll)
    {
        $this->m_bScroll = $bScroll;
    }
    public function setNumber($number)
    {
        $this->m_nNumber = $number;
    }
    public function setRow($nrow)
    {
        $this->m_nRow = $nrow;
    }
    
    public function setCol($ncol)
    {
        $this->m_nCol = $ncol;
    }
    
    public function setWidth($nWidth)
    {
        $this->m_nWidth = $nWidth;
    }
     public function setHeight($nHeight)
    {
        $this->m_nHeight = $nHeight;
    }
     public function setCellWidth($m_nCellWidth)
    {
        $this->m_nCellWidth = $m_nCellWidth;
    }
     public function setCellHeight($nCellHeight)
    {
        $this->m_nCellHeight = $nCellHeight;
    }
        
    public function settag($idtag)
    {
        $this->m_div = $idtag;
    }
    
    public function getNumberPage()
    {
        if(isset($_GET['page']) && (int)$_GET['page']) {
                $page = $_GET['page'];
            } else { //neu chua xac dinh, thi tim so trang
                $query = "SELECT COUNT(id) FROM gallery";
                $res = mysqli_query($connection,$query) or die('Could not select gallery '.mysqli_error($connect));
                $rows = mysqli_fetch_array($res, MYSQLI_NUM);
                $record = $rows[0];
                if($record > $display) {
                    $page = ceil($record/$display);
                } else {
                    $page = 1;
                }
            }
            return $page;
    }
    public function display($curPage)
    {
        $width = 'width:'.$this->m_nWidth.'px;';
        $height = 'height:'.$this->m_nHeight.'px;';
        $sScroll ='';
        if((bool)$this->m_bScroll)
                $sScroll = 'overflow: scroll;';
        $closeDiv = '</div>';
        $gridDiv = '<div class="'.$this->m_div.'" style = "'.$width.$height.$sScroll.'">';
        $rowDiv = '<div class="row">';
        $cellDiv ='<div class ="cell" style="width: 120px;">';
        
        //Start print grid
        echo $gridDiv;
        
        
        $connect = mysql_connect("localhost", "root","") or die("couldn't connect");
        mysql_select_db("tripviet") or die("couldn't found");
        
            
            
            
    if($this->m_bShow)
        $squery = "select * from gallery where bshow=1";
    else 
        $squery = "select * from gallery where bshow=0";
    
    $rs = mysql_query($squery); 
    
    
    while($row=mysql_fetch_assoc($rs))
    {
        $nIdImg = $row['id'];
        echo $rowDiv;       
        $productCell = new CCellImage();
        if($this->m_bShow)
          $productCell->setcheck ((bool)true);      
        else
            $productCell->setcheck ((bool)false);
        $productCell->setHeight($this->m_nCellHeight);
        $productCell->setWidth($this->m_nCellWidth);
        $productCell->setsource($row['path']);
        $productCell->show();
        echo $closeDiv;

    }                                       
        echo $closeDiv;
    }
}
?>
